package com.gt.util.serialize;

import org.nustaq.serialization.FSTConfiguration;

/**
 * @author WUREN
 * @desc FST序列化/反序列化工具类
 * @create 2019-02-26 0:16
 **/
public class FstUtil {
    private static ThreadLocal<FSTConfiguration> confs = new ThreadLocal(){
        public FSTConfiguration initialValue() {
            return FSTConfiguration.createDefaultConfiguration();
        }
    };

    private static FSTConfiguration getFST(){
        return confs.get();
    }

    protected static <T> byte[] serializer(T t){
        return getFST().asByteArray(t);
    }


    protected static <T> T deserializer(byte[] bytes, Class<T> clazz) {
        return  (T)getFST().asObject(bytes);
    }
}
